package com.example.shardingSphere;

import com.example.shardingSphere.entity.Order;
import com.example.shardingSphere.entity.UserInfo;
import com.example.shardingSphere.service.OrderServiceImpl;
import com.example.shardingSphere.service.UserInfoService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {ShardingSphereApplication.class})
public class ShardingSphereApplicationTests2 {


    @Resource
    private UserInfoService userInfoService;


    @Autowired
    private OrderServiceImpl orderService;


    @Test
    public void ge() {
        List<UserInfo> userList = userInfoService.ge();
        userList.forEach(userInfo -> {
            System.out.println(userInfo.toString());
        });
    }


    @Test
    public void ge1() {
        List<UserInfo> userList = userInfoService.ge();
        userList.forEach(userInfo -> {
            System.out.println(userInfo.toString());
        });
    }

    @Test
    public void user_insert1() {
        UserInfo userInfo;
        List<UserInfo> list = new ArrayList<>();
        int start = 20;
        int limit = 1;
        for (int i = start; i < start + limit; i++) {
            list.add(new UserInfo().setAge(i).setName("test_" + i));

        }
        userInfoService.saveBatch(list, list.size());
    }

    @Test
    public void order_insert1() {
        orderService.insert1();
    }

    @Test
    public void order_getList() {
        Map<String, Object> map = orderService.getOrderList();
        Object orders = map.get("orders");
        List<Order> list = (List<Order>) orders;
        list.forEach(order -> {
            System.out.println(order.toString());
        });
        System.out.println();
    }

//    @Resource
//    private UserMapper userMapper;
//
//    @Test
//    public void ge() {
//        LambdaQueryWrapper<UserInfo> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.ge(UserInfo::getAge, "5")
//                .orderByDesc(UserInfo::getId);
//        List<UserInfo> userList = userMapper.selectList(queryWrapper);
//        userList.forEach(userInfo -> {
//            System.out.println(userInfo.toString());
//        });
//    }
}
